//
//  GFCollectCell.m
//  GoodFood
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 荣伟峰. All rights reserved.
//

#import "GFCollectCell.h"

@interface GFCollectCell ()
@property (nonatomic, strong) UIImageView *titleImage;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *countLabel;
@property (nonatomic, strong) UILabel *subLabel;
@property (nonatomic, strong) UILabel *levelLabel;
@end

@implementation GFCollectCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.titleImage = [[UIImageView alloc] init];
        self.titleImage.layer.masksToBounds = YES;
        self.titleImage.layer.cornerRadius = 30;
        [self.contentView addSubview:self.titleImage];
        
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        
        
        self.countLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.countLabel];
        
        
        self.subLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.subLabel];
        
        
        self.levelLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.levelLabel];
        
        
    }
    
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleImage.frame = CGRectMake(ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 60, ScreenWidth / 375.0 * 60);
    
    self.titleLabel.frame = CGRectMake(ScreenWidth / 375.0 * 90, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 230, ScreenWidth / 375.0 * 30);
    self.titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    self.titleLabel.font = [UIFont systemFontOfSize:17];
    
    CGFloat width2 = [GFCalculateWidthOrHeigth stringWidth:self.countLabel.text withHeigth:ScreenWidth / 375.0 * 30 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
    
    self.countLabel.frame = CGRectMake(ScreenWidth / 375.0 * 90, ScreenWidth / 375.0 * 60, width2, ScreenWidth / 375.0 * 20);
    self.countLabel.textColor = [UIColor redColor];
    
    CGFloat width3 = [GFCalculateWidthOrHeigth stringWidth:self.subLabel.text withHeigth:ScreenWidth / 375.0 * 20 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    self.subLabel.frame = CGRectMake(ScreenWidth / 375.0 * 90 + width2, ScreenWidth / 375.0 * 60, width3, ScreenWidth / 375.0 * 20);
    self.subLabel.font = [UIFont systemFontOfSize:15];
    
    self.levelLabel.frame = CGRectMake(ScreenWidth / 375.0 * 330, ScreenWidth / 375.0 * 40, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 20);
    self.levelLabel.layer.masksToBounds = YES;
    self.levelLabel.layer.cornerRadius = 10;
}

- (void)setDeModel:(GFDetialsModel *)deModel {
    if (_deModel != deModel) {

        _deModel = deModel;
    }
    if (deModel.thumb_image_url) {
        [self.titleImage setImageWithURL:[NSURL URLWithString:deModel.thumb_image_url] placeholderImage:[UIImage imageNamed:@"category_1"]];
    }
    
    self.titleLabel.text = deModel.name;
    
    if (deModel.health_light == 1) {
        self.levelLabel.backgroundColor = [UIColor greenColor];
    } else if (deModel.health_light == 2) {
        self.levelLabel.backgroundColor = [UIColor yellowColor];
    } else {
        self.levelLabel.backgroundColor = [UIColor redColor];
    }
    
    self.countLabel.text = self.deModel.calory;
    
    NSString *str = [NSString stringWithFormat:@"大卡/%@克", self.deModel.weight];
    
    self.subLabel.text = str;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
